package com.longer.playhelper.view.fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.longer.playhelper.Application;
import com.longer.playhelper.R;
import com.longer.playhelper.adapter.FragmentLoveAdapter;
import com.longer.playhelper.modle.bean.Love;
import com.longer.playhelper.presenter.Fragement_PlayPresenter;
import com.longer.playhelper.view.activity.Add_loveActivity;
import com.longer.playhelper.view.iview.IFragment_PlayView;
import com.tapadoo.alerter.Alerter;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class PlayFragment extends Fragment implements IFragment_PlayView {

    @Bind(R.id.recycle_item_menu_love)
    RecyclerView recycleItemMenuLove;
    private View view;
    Context context;

    private Fragement_PlayPresenter menuPresenter = new Fragement_PlayPresenter(this);

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_play, container, false);
        context = getActivity();
        init();
        ButterKnife.bind(this, view);
        return view;
    }

    private void init() {
        menuPresenter.setMenuLove();
        view.findViewById(R.id.fab_love).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Application.my == null) {
                    Alerter.create(getActivity())
                            .setTitle("登录用户才能发布哦~")
                            .setBackgroundColorRes(R.color.colorAccent)
                            .show();
                }else{
                    startActivity(new Intent(context, Add_loveActivity.class));
                }
            }
        });
    }


    @Override
    public void setmenu_love(List<Love> list) {
//        view.findViewById(R.id.ll_item_menu_love).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {//底部更多表白按钮
//                startActivity(new Intent(context, LoveActivity.class));
//            }
//        });
        recycleItemMenuLove.setHasFixedSize(true);

        LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
        recycleItemMenuLove.setLayoutManager(layoutManager);

        FragmentLoveAdapter mAdapter = new FragmentLoveAdapter(list, context);
        recycleItemMenuLove.setAdapter(mAdapter);
//        mAdapter.addEnditem();

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
